/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.weixin.service;

import com.apache.portal.weixin.core.common.LoadService;
import com.apache.portal.weixin.entity.BaseVo;
import com.apache.portal.weixin.entity.recv.WxRecvMsg;
import com.apache.portal.weixin.entity.recv.WxRecvPicMsg;
import com.apache.portal.weixin.entity.send.WxSendMsg;
import com.apache.portal.weixin.entity.send.WxSendTextMsg;
import com.apache.tools.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * description:
 *
 * @author dyhou 创建时间：2017-3-6
 */
public class OtherServiceImpl extends AbstractService {

    private Logger log = LoggerFactory.getLogger(getClass());

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     */
    public Object execute(BaseVo vo) throws Exception {
        WxRecvMsg wxRecvMsg = vo.getWxRecvMsg();
        WxSendMsg sendMsg = null;
        if (wxRecvMsg instanceof WxRecvPicMsg) {
            sendMsg = sendRecvPicMsg(wxRecvMsg);
        }

        return sendMsg;
    }

    /**
     * description:  图片消息
     */
    private WxSendMsg sendRecvPicMsg(WxRecvMsg wxRecvMsg) {
        WxRecvPicMsg event = (WxRecvPicMsg) wxRecvMsg;
        WxSendMsg sendMsg = LoadService.getInstance().getTools().builderSendByRecv(wxRecvMsg);
        String picUrl = event.getPicUrl();
        String mediaId = event.getMediaId();
        event.setMsgType("images");
        //WxSendPicMsg pics = new WxSendPicMsg(sendMsg, mediaId);
        log.info("image====" + picUrl + "|" + mediaId);
        Map<String, String> map = LoadService.getInstance().getTools()
                .getMedia(mediaId, event.getFromUser());
        log.info("上传结果====" + map);
        String content = "资料上传失败";
        if (StrUtil.isNotNull(map.get("floderName"))) {
            content = "资料上传成功";
        }
        WxSendTextMsg text = new WxSendTextMsg(sendMsg, content);
        return text;
    }
}
